﻿
//查看订单状态进度
app.controller('FormController', ['$scope', '$location', 'FormbyService', function ($scope, $location, FormbyService) {
    //alert("++");

    var formID = 1;

    var reg = new RegExp("(^|\\?|&)FormID=([^&]*)(\\s|&|$)", "i");

    if (reg.test(location.href))

        formID = unescape(RegExp.$2.replace(/\+/g, " "));

    var postData = {
        FormID: formID
    }
    //alert(formID);
    FormbyService.Formby(postData)
        .success(function (resp) {


            var zt = {
                bs: '',
                data: [],
                mes: ''
            };

            var zt = resp;


            //zt = resp;
            $scope.items = zt.data;
            //alert(zt.bs)
            if (parseInt(zt.bs) > 0) {
            }
            else {
                $scope.items = [
                    {
                        Call: "",
                        ConText: "没有数据",
                        LogTime: "",
                        Name: "",
                        OperaType: "",
                        PreTime: "",
                        Tip: "",
                    },
                ];
            }
        })
        .error(function (resp) { console.log(resp) });

}]);
//订单信息-下订单
app.controller('ConfirmOrderController', ['$scope', '$window', '$location', 'WaltandAddressService', 'OrderService', 'GetSendAddFromMerIdService', function ($scope, $window, $location, WaltandAddressService, OrderService, GetSendAddFromMerIdService) {
    //获取URL参数，即：获取商户ID。此做法死板，最好能用search()但未能实现
    var ContactID = $location.absUrl().substring($location.absUrl().lastIndexOf("=") + 1);
    console.log("ContactID");
    console.log(ContactID);
    // 定义变量
    var vm = $scope.vm = {};
    vm.addresses = [];//地址数组
    vm.paywalts = [];//钱包数组
    vm.DeliveryDate = [];//日期数组
    vm.DeliveryTime = [];//时间数组
    vm.selectionW = [];

    //vm.address_order = "";//用户下单手写的详细地址
    //vm.name_order = "";//下单的用户名字
    //vm.phone_order = "";//下单的用户联系方式
    $scope.phone_order = "";//下单的用户联系方式

    $scope.DishList = [];//菜品列表
    $scope.CountArr = [];//菜品数量
    $scope.Total = '';//金额
    $scope.Discount = '';//数量
    $scope.TotalPoint = '';//消耗的积分
    $scope.ShopInfo = '';//商户信息

    //function getCookie(name) {
    //    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    //    if (arr = document.cookie.match(reg))
    //        return unescape(arr[2]);
    //    else
    //        return null;
    //}
    //var a = getCookie();
    //console.log(document.cookie);

    //截取url数据方法
    var getParam = function (name) {
        var search = document.location.search;
        //alert(search);
        var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
        var matcher = pattern.exec(search);
        var items = null;
        if (null != matcher) {
            try {
                items = decodeURIComponent(decodeURIComponent(matcher[1]));
            } catch (e) {
                try {
                    items = decodeURIComponent(matcher[1]);
                } catch (e) {
                    items = matcher[1];
                }
            }
        }
        return items;
    };
    //var a = getParam('shopnumber');
    //alert(a);
    $scope.vm.selectionA = JSON.parse(getParam('selectAddress'));
    console.log($scope.vm.selectionA)

    //数量
    $scope.varlist = {
        pack: 0
    }
    vm.BZ = '';//备注

    $scope.orderform = {
        Contact: {
            ContactName: "",
            ContactAddress: "",
            ContactCall: "",
        },
        Walt: $scope.vm.selectionW,
        BZ: '',
        Date: '',
        Time: '',
        Type: 200001,//用于鉴别用户，200001为一般用户，200002为企业用户
        isTake: '',
        Total: '',
    };

    // 默认选择为派送
    var isTake1 = document.getElementById("isTake1");
    isTake1.className += " " + "zhuangtai";
    var isTake = 1; // 默认派送 1：派送；2：自取


    // 是否自取的事件
    $scope.take = function (v) {
        if (v == 1) {
            isTake = 1;
            var isTake1 = document.getElementById("isTake1");
            isTake1.className += " " + "zhuangtai";
            var isTake2 = document.getElementById("isTake2");
            isTake2.className = "xuanze f-right";

            //组装数据包
            var postData = {
                ID: $scope.vm.selectionW.ID,
                isTake: 1,
            }

            //计算优惠信息
            OrderService.list(postData)
                .success(function (resp) {
                    console.log(resp);
                    console.log("点击时计算优惠信息");
                    $scope.DishList = resp.data.DishList;
                    $scope.CountArr = resp.data.CountArr;
                    $scope.Total = resp.data.Total;
                    $scope.Discount = resp.data.Discount;
                    //alert("总价：" + $scope.Total + " 优惠：" + $scope.Discount);
                    $scope.TotalPoint = resp.data.TotalPoint;
                    $scope.ShopInfo = resp.shopinfo;
                    $scope.delpackmon = resp.data;
                    $scope.backCount = function (dishesid) {
                        for (var i in $scope.DishList) {
                            if ($scope.DishList[i].DishesID == dishesid) {
                                return $scope.CountArr[i];
                            }
                        }
                    }
                    $scope.packTotal = function () {
                        $scope.varlist.pack = 0;
                        for (var j = 0; j < $scope.CountArr.length; j++) {
                            $scope.varlist.pack = $scope.varlist.pack + $scope.CountArr[j] * $scope.DishList[j].DelPackMon;//商品数量*商品包装费
                        }
                        return $scope.varlist.pack;
                    }
                })
                .error(function (resp) { console.log(resp) });
        } else {
            isTake = 2;
            var isTake2 = document.getElementById("isTake2");
            isTake2.className += " " + "zhuangtai";
            var isTake1 = document.getElementById("isTake1");
            isTake1.className = "xuanze f-right";

            //组装数据包
            var postData = {
                ID: $scope.vm.selectionW.ID,
                isTake: 2,
            }

            //计算优惠信息
            OrderService.list(postData)
                .success(function (resp) {
                    console.log(resp);
                    console.log("点击时计算优惠信息");
                    $scope.DishList = resp.data.DishList;
                    $scope.CountArr = resp.data.CountArr;
                    $scope.Total = resp.data.Total;
                    $scope.Discount = resp.data.Discount;
                    //alert("总价：" + $scope.Total + " 优惠：" + $scope.Discount);
                    $scope.TotalPoint = resp.data.TotalPoint;
                    $scope.ShopInfo = resp.shopinfo;
                    $scope.delpackmon = resp.data;
                    $scope.backCount = function (dishesid) {
                        for (var i in $scope.DishList) {
                            if ($scope.DishList[i].DishesID == dishesid) {
                                return $scope.CountArr[i];
                            }
                        }
                    }
                    $scope.packTotal = function () {
                        $scope.varlist.pack = 0;
                        for (var j = 0; j < $scope.CountArr.length; j++) {
                            $scope.varlist.pack = $scope.varlist.pack + $scope.CountArr[j] * $scope.DishList[j].DelPackMon;//商品数量*商品包装费
                        }
                        return $scope.varlist.pack;
                    }
                })
                .error(function (resp) { console.log(resp) });
        }
    }

    $scope.aa = function (re) {
        console.log(re);
        for (var i in $scope.vm.paywalts) {
            if ($scope.vm.paywalts[i].bb = 2) {
            }
        }
        $scope.orderform.Walt = re;
        $scope.orderform.Type = 200001;
        //$scope.orderform = {
        //    Walt: re,
        //    //Contact: $scope.vm.selectionA,
        //    Type: 200001//用于鉴别用户，200001为一般用户，200002为企业用户
        //}
        console.log($scope.orderform);
        $scope.vm.selectionW = re;
        $scope.vm.selectionW.bb = 1;
        console.log(1);
        //组装数据包
        var postData = {
            ID: $scope.vm.selectionW.ID,
            isTake: isTake,
        }

        //计算优惠信息
        OrderService.list(postData)
            .success(function (resp) {
                console.log(resp);
                console.log("点击时计算优惠信息");
                $scope.DishList = resp.data.DishList;
                $scope.CountArr = resp.data.CountArr;
                $scope.Total = resp.data.Total;
                $scope.Discount = resp.data.Discount;
                //alert("总价：" + $scope.Total + " 优惠：" + $scope.Discount);
                $scope.TotalPoint = resp.data.TotalPoint;
                $scope.ShopInfo = resp.shopinfo;
                $scope.delpackmon = resp.data;
                $scope.backCount = function (dishesid) {
                    for (var i in $scope.DishList) {
                        if ($scope.DishList[i].DishesID == dishesid) {
                            return $scope.CountArr[i];
                        }
                    }
                }
                $scope.packTotal = function () {
                    $scope.varlist.pack = 0;
                    for (var j = 0; j < $scope.CountArr.length; j++) {
                        $scope.varlist.pack = $scope.varlist.pack + $scope.CountArr[j] * $scope.DishList[j].DelPackMon;//商品数量*商品包装费
                    }
                    return $scope.varlist.pack;
                }
            })
            .error(function (resp) { console.log(resp) });
    }

    //获取钱包、地址、送餐时间等信息
    WaltandAddressService.list()
        .success(function (resp) {
            console.log(resp);
            vm.paywalts = resp.walt;//钱包集合
            $scope.vm.selectionW = vm.paywalts[0];//选择的钱包
            console.log($scope.vm.selectionW);
            vm.selectionW.bb = 1;

            //if (vm.addresses.length > 0) {
            //    if (ContactID != '') {
            //        for (var i in vm.addresses) {
            //            if (vm.addresses[i].ID == ContactID) {
            //                $scope.vm.selectionA = vm.addresses[i];
            //                console.log($scope.vm.selectionA);
            //            }
            //        }
            //    } else {
            //        $scope.vm.selectionA = vm.addresses[0];//选择的地址

            //    }
            //}
            //else {
            //    document.getElementById('Address').text = "点击添加送餐地址"
            //}

            //截取url数据方法
            var getParam = function (name) {
                var search = document.location.search;
                //alert(search);
                var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
                var matcher = pattern.exec(search);
                var items = null;
                if (null != matcher) {
                    try {
                        items = decodeURIComponent(decodeURIComponent(matcher[1]));
                    } catch (e) {
                        try {
                            items = decodeURIComponent(matcher[1]);
                        } catch (e) {
                            items = matcher[1];
                        }
                    }
                }
                return items;
            };
            //var a = getParam('shopnumber');
            //alert(a);
            var postdata_addresslist = {
                MerId: getParam('shopnumber')
            }
            console.log(postdata_addresslist)
            WaltandAddressService.list_address(postdata_addresslist)
                .success(function (res) {
                    console.log(res);
                    vm.addresses = res.rows;//地址集合

                    if (vm.addresses.length > 0) {
                        if (ContactID != '') {
                            for (var i in vm.addresses) {
                                if (vm.addresses[i].ID == ContactID) {
                                    $scope.vm.selectionA = vm.addresses[i];
                                    console.log($scope.vm.selectionA);
                                }
                            }
                        } else {
                            console.log(getParam('isAdd'));
                            if (getParam('isAdd') == 1) {
                                $scope.vm.selectionA = vm.addresses[vm.addresses.length - 1];//选择的地址
                            } else {
                                $scope.vm.selectionA = vm.addresses[0];//选择的地址
                            }



                        }
                    }
                    else {
                        document.getElementById('Address').text = "点击添加送餐地址"
                    }
                })




            vm.DeliveryDate = resp.opendate;//日期集合
            vm.selectionD = vm.DeliveryDate[0];//选择的日期
            vm.DeliveryTime = resp.opentiem;//时间集合
            vm.selectionT = vm.DeliveryTime[0];//选择的时间

            console.log($scope.vm.paywalts[0].ID);
            //组装数据包
            var postData = {
                ID: $scope.vm.paywalts[0].ID,
                isTake: isTake,
            }

            //计算优惠信息
            OrderService.list(postData)
                .success(function (resp) {
                    console.log(resp);
                    console.log("初始化计算优惠信息");
                    $scope.DishList = resp.data.DishList;
                    $scope.CountArr = resp.data.CountArr;
                    $scope.Total = resp.data.Total;
                    $scope.Discount = resp.data.Discount;
                    //alert("总价：" + $scope.Total + " 优惠：" + $scope.Discount);
                    $scope.TotalPoint = resp.data.TotalPoint;
                    $scope.ShopInfo = resp.shopinfo;
                    console.log("初始化计算包装费信息")
                    $scope.delpackmon = resp.data;
                    console.log($scope.delpackmon);
                    $scope.backCount = function (dishesid) {
                        for (var i in $scope.DishList) {
                            if ($scope.DishList[i].DishesID == dishesid) {
                                return $scope.CountArr[i];
                            }
                        }
                    }
                    $scope.packTotal = function () {
                        $scope.varlist.pack = 0;
                        for (var j = 0; j < $scope.CountArr.length; j++) {
                            $scope.varlist.pack = $scope.varlist.pack + $scope.CountArr[j] * $scope.DishList[j].DelPackMon;//商品数量*商品包装费
                        }
                        return $scope.varlist.pack;
                    }
                })
                .error(function (resp) { console.log(resp) });
        })
        .error(function (resp) { console.log(resp) });

    //商户派送范围数组
    $scope.merrange = [];

    //商户选择的派送范围
    $scope.psfw = "";
    $scope.xxdz = "";//手写的送餐地址

    //根据商户id获取改商户下的所有派送范围
    GetSendAddFromMerIdService.list()
        .success(function (resp) {
            $scope.merrange = resp.list;
            console.log('派送', resp);
            console.log('派送范围', $scope.merrange);
            console.log("收货地址", vm.addresses);
        })
        .error(function (resp) { console.log(resp) });

    $scope.$watch("", function (newVal, oldVal) {//+vm.BZ
        //alert(vm.selectionW.name+"+");
        //支付时使用到的实体包
        //$scope.orderform = {
        //    Contact: vm.selectionA,
        //    Walt: vm.selectionW,
        //    BZ: '',
        //    Date: '',
        //    Time: '',
        //    Type: 200001//用于鉴别用户，200001为一般用户，200002为企业用户
        //};
        //alert($scope.orderform.Walt + "+")
        //定义返回实体格式
        var whichwalt = {
            ID: '',
            Name: '',
            PricType: 0,
            PriTxt: '',
        };

        whichwalt = newVal;
        //组装数据包
        var postData = {
            ID: whichwalt.ID,
            PricType: whichwalt.PricType,
            lx: 1
        }
        //计算优惠信息
        OrderService.list(postData)
            .success(function (resp) {
                console.log(resp);
                $scope.DishList = resp.data.DishList;
                $scope.CountArr = resp.data.CountArr;
                $scope.Total = resp.data.Total;
                $scope.Discount = resp.data.Discount;
                //alert("总价：" + $scope.Total + " 优惠：" + $scope.Discount);
                $scope.TotalPoint = resp.data.TotalPoint;
                $scope.ShopInfo = resp.shopinfo;

                $scope.backCount = function (dishesid) {
                    for (var i in $scope.DishList) {
                        if ($scope.DishList[i].DishesID == dishesid) {
                            return $scope.CountArr[i];
                        }
                    }
                }
                $scope.packTotal = function () {
                    $scope.varlist.pack = 0;
                    for (var j = 0; j < $scope.CountArr.length; j++) {
                        $scope.varlist.pack = $scope.varlist.pack + $scope.CountArr[j] * $scope.DishList[j].DelPackMon;//商品数量*商品包装费
                    }
                    return $scope.varlist.pack;
                }
            })
            .error(function (resp) { console.log(resp) });
    }, true);
    //提交订单
    $scope.BookOrder = function (date, time, bz, total) {
        $scope.orderform.Date = date;
        $scope.orderform.Time = time;
        $scope.orderform.BZ = bz;
        $scope.orderform.Total = total;
        $scope.orderform.Walt = vm.selectionW;
        //$scope.orderform.Contact = vm.selectionA;
        $scope.orderform.isTake = isTake;
        //$scope.orderform.Contact.ContactAddress = $scope.psfw + $scope.xxdz;
        //$scope.orderform.Contact.ContactCall = $scope.phone_order+"";

        //console.log($scope.orderform);

        //if ($scope.psfw == "" || $scope.orderform.Contact.xxdz == "" || $scope.orderform.Contact.ContactName == "" || $scope.orderform.Contact.ContactCall == "") {
        //    alert("请填写配送信息！");
        //    return;
        //}

        console.log(vm.selectionA);
        $scope.orderform.Contact.ContactAddress = vm.selectionA.AddrContent;
        $scope.orderform.Contact.ContactCall = vm.selectionA.TelNum + "";
        $scope.orderform.Contact.ContactName = vm.selectionA.Name;
        if ($scope.orderform.Contact.ContactCall == "" || $scope.orderform.Contact.ContactAddress == "" || $scope.orderform.Contact.ContactName == "") {
            alert("请填写配送信息！");
            return;
        }


        OrderService.book($scope.orderform)
            .success(function (resp) {
                if (resp == "10") {
                    window.location = '/Order/TiJiaoOrder'; //打开确认订单页
                } else if (resp.msg == 'success') {
                    //alert(resp.appId);
                    onBridgeReady(resp);

                    function onBridgeReady(resp) {
                        WeixinJSBridge.invoke(
                            'getBrandWCPayRequest', {
                                "appId": resp.appId,     //公众号名称，由商户传入
                                "timeStamp": resp.timeStamp,         //时间戳，自1970年以来的秒数
                                "nonceStr": resp.nonceStr, //随机串
                                "package": resp.packageValue,
                                "signType": "MD5",         //微信签名方式:
                                "paySign": resp.paySign //微信签名
                            },
                            function (res) {
                                if (res.err_msg == "get_brand_wcpay_request:ok") {
                                    //alert("支付成功,请稍后查询余额,如有疑问,请联系管理员.");
                                    window.location.href = '/Order/OrderList';
                                }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                            });
                    }
                    //window.location = '/JsApiPay/Index';//打开微信支付页面----------jsapi
                } else {
                    //alert(123);
                    //alert(resp);
                    console.log(resp)

                }
            })
            .error(function (resp) { console.log("错误：" + resp) });
        //}
    }

}]);
//获取用户订单列表
app.controller('OrderListController', ['$scope', '$http', '$location', 'OrderListService', function ($scope, $http, $location, OrderListService) {
    ////配置分页基本参数
    //$scope.paginationConf = {
    //    currentPage: 1,//当前页
    //    itemsPerPage: 5//每页显示的数量
    //};
    //var GetAllEmployee = function () {
    //    var postData = {
    //        Type: "0",
    //        pageIndex: $scope.paginationConf.currentPage,
    //        pageSize: $scope.paginationConf.itemsPerPage
    //    }

    //    //获取订单列表页
    //    OrderListService.list(postData)
    //        .success(function (resp) {
    //            $scope.paginationConf.totalItems = resp.total;
    //            $scope.OrderList = resp.rows;
    //            console.log($scope.OrderList);
    //        })
    //        .error(function (resp) { console.log(resp) });
    //}

    ///***************************************************************
    //当页码和页面记录数发生变化时监控后台查询
    //如果把currentPage和itemsPerPage分开监控的话则会触发两次后台事件。 
    //***************************************************************/
    //$scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', GetAllEmployee);
    var index = 1;
    function lowEnough() {
        var pageHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight);
        var viewportHeight = window.innerHeight ||
            document.documentElement.clientHeight ||
            document.body.clientHeight || 0;
        var scrollHeight = window.pageYOffset ||
            document.documentElement.scrollTop ||
            document.body.scrollTop || 0;
        //console.log(pageHeight);
        //console.log(viewportHeight);
        //console.log(scrollHeight);
        return pageHeight - viewportHeight - scrollHeight < 20;
    }



    function doSomething() {
        var postData = {
            Type: "0",
            pageIndex: index,
            pageSize: 5
        }
        //获取订单列表页
        OrderListService.list(postData)
            .success(function (resp) {
                console.log(resp);
                var item = resp.rows;
                // 获取信息，是否允许评价
                $http.get('/Order/GetOrder_Key').success(function (resp) {
                    if (resp != "" || resp != null) {
                        console.log(resp[0]);
                        var tag = resp[0].ComOpen; // 是否允许评价,1-是，0-否
                        console.log(tag);
                        if (item.length > 0) {
                            var htmlStr = "";
                            for (var i = 0; i < item.length; i++) {
                                if (tag == 1) {
                                    if (item[i].vof.IsEva == 0) {
                                        if (item[i].vof.IsPay == 2 || item[i].vof.IsPay == 4) {
                                            if (item[i].vof.ConIsEva == 2) {
                                                htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a >" /*+ item[i].vof.MerName*/
                                                    + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                                    + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                                    + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                                    + "</p></div><div class='clearfix'></div></div>"
                                                    + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                                    + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                                    + "<a href='/Order/Evaluate?FormID=" + item[i].vof.FormID + "'>去评价</a>"
                                                    + "</p></div>"
                                                    + "</div>";
                                            } else {
                                                htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" /*+ item[i].vof.MerName*/
                                                    + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                                    + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                                    + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                                    + "</p></div><div class='clearfix'></div></div>"
                                                    + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                                    + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                                    + "<a href='#'>不予评价</a>"
                                                    + "</p></div>"
                                                    + "</div>";
                                            }
                                        } else if (item[i].vof.IsPay == 0) {
                                            htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" /*+ item[i].vof.MerName*/
                                                + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                                + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                                + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                                + "</p></div><div class='clearfix'></div></div>"
                                                + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                                + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                                + "<a href='/Order/RePayment?MerID=" + item[i].vof.FormMerID + "&FormID=" + item[i].vof.FormID + "'>继续支付</a>"
                                                + "</p></div>"
                                                + "</div>";
                                        } else {
                                            htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" /*+ item[i].vof.MerName*/
                                                + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                                + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                                + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                                + "</p></div><div class='clearfix'></div></div>"
                                                + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                                + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                                + "<a href='#'>支付失败</a>"
                                                + "</p></div>"
                                                + "</div>";
                                        }
                                    } else {
                                        htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" /*+ item[i].vof.MerName*/
                                            + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                            + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                            + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                            + "</p></div><div class='clearfix'></div></div>"
                                            + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                            + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                            + "<a ng-click='togoEvaluate(item.vof.FormID)'>已评价</a>"
                                            + "</p></div>"
                                            + "</div>";
                                    }
                                }

                                //else {
                                //    if (item[i].vof.IsEva == 0) {
                                //        if (item[i].vof.IsPay == 2 || item[i].vof.IsPay == 4) {
                                //            htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" + item[i].vof.MerName
                                //                + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                //                + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                //                + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                //                + "</p><p class='state'><a href=\"\\Form\\Index?FormID=" + item[i].vof.FormID + "\">订单状态流程</p></div><div class='clearfix'></div></div>"
                                //                + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                //                + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                //                + "<a href='#'>不予评价</a>"
                                //                + "</p></div>"
                                //                + "</div>";
                                //        } else if (item[i].vof.IsPay == 0) {
                                //            htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" + item[i].vof.MerName
                                //                + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                //                + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                //                + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                //                + "</p><p class='state'><a href=\"\\Form\\Index?FormID=" + item[i].vof.FormID + "\">订单状态流程</p></div><div class='clearfix'></div></div>"
                                //                + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                //                + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                //                + "<a href='/Order/RePayment?MerID=" + item[i].vof.FormMerID + "&FormID=" + item[i].vof.FormID + "'>继续支付</a>"
                                //                + "</p></div>"
                                //                + "</div>";
                                //        } else {
                                //            htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" + item[i].vof.MerName
                                //                + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                //                + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                //                + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                //                + "</p><p class='state'><a href=\"\\Form\\Index?FormID=" + item[i].vof.FormID + "\">订单状态流程</p></div><div class='clearfix'></div></div>"
                                //                + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                //                + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                //                + "<a href='#'>支付失败</a>"
                                //                + "</p></div>"
                                //                + "</div>";
                                //        }
                                //    } else {
                                //        htmlStr += "<div class='info'><div class='cont_top'><div class='pic'></div><a>" + item[i].vof.MerName
                                //            + "</a><div class='clearfix'></div></div><div class='line'></div><div class='cont_middle'><div class='cont_left'><p class='name'><span>" + item[i].FormDisheName[0]
                                //            + "等</span><span>" + item[i].FormDisheName.length + "</span>件商品</p><p class='time'>" + item[i].vof.FormTime
                                //            + "</p></div><div class='cont_right'><p class='money'>￥" + item[i].vof.FormPayMon * 0.01
                                //            + "</p><p class='state'><a href=\"\\Form\\Index?FormID=" + item[i].vof.FormID + "\">订单状态流程</p></div><div class='clearfix'></div></div>"
                                //            + "<div class='cont_bottom' ng-controller='AllLinkCtrl'><p class='continue'><a href='/Order/OrderDetail?FormID=" + item[i].vof.FormID + "'>查看详情</a></p>"
                                //            + "<p class='evaluate' ng-if='item.vof.IsPay==2||item.vof.IsPay==4'>"
                                //            + "<a ng-click='togoEvaluate(item.vof.FormID)'>已评价</a>"
                                //            + "</p></div>"
                                //            + "</div>";
                                //    }
                                //}

                            }
                            $('#content').append(htmlStr);
                            index++;
                            pollScroll();//继续循环
                            $('#spinner').hide();//正在加载字样隐藏
                        } else {
                            htmlStr = "<div style='text-align:center'>没有更多了~</div>";// class='info'
                            $('#content').append(htmlStr);
                            $('#spinner').hide();//正在加载字样隐藏
                        }
                    } else {
                        console.log("系统异常");
                    }

                });


            })
            .error(function (resp) { console.log(resp) });
    }

    function checkScroll() {
        if (!lowEnough()) return pollScroll();
        $('#spinner').show();//正在加载字样显示
        setTimeout(doSomething, 900);

    }
    function pollScroll() {
        setTimeout(checkScroll, 1000);
    }
    checkScroll();

    //显示选中按钮的背景

    //$radio5.click (function () {
    //    alert("+");
    //    var isChecked = false;

    //    $(this).addClass("cla");
    //    $(this).siblings().removeClass("cla");

    //}

    //)
    //$scope.$watch("vm.selectionW", function () {
    //    alert(vm.selectionW.name + '|' + vm.selectionW.ID)
    //}, true);


    $scope.addEvaInfo = {
        FormID: '',
        EvaTxt: '',
        EvaStars: '',
        GoodDishes: []
    };
    $scope.getDishLish = function (u) {
        $scope.EvaDishName = u.FormDisheName;
        $scope.EvaDishID = u.FormDisheID;
        $scope.addEvaInfo.FormID = u.vof.FormID;
    };
    $scope.isStar1 = false;
    $scope.isStar2 = false;
    $scope.isStar3 = false;
    $scope.isStar4 = false;
    $scope.isStar5 = false;
    //评分
    $scope.putstar = function (star) {
        console.log(star);
        $scope.addEvaInfo.EvaStars = star;
        console.log($scope.addEvaInfo.EvaStars);

    };
    //选择推荐菜
    //$scope.selected = [];
    //$scope.selectedTags = [];
    var updateSelected = function (action, id, name) {
        if (action == 'add' && $scope.addEvaInfo.GoodDishes.indexOf(id) == -1) {
            $scope.addEvaInfo.GoodDishes.push(id);
            //$scope.selected.push(id);
            //$scope.selectedTags.push(name);
        }
        if (action == 'remove' && $scope.addEvaInfo.GoodDishes.indexOf(id) != -1) {
            var idx = $scope.addEvaInfo.GoodDishes.indexOf(id);
            $scope.addEvaInfo.GoodDishes.splice(idx, 1);
            //$scope.selected.splice(idx, 1);
            //$scope.selectedTags.splice(idx, 1);
        }
    }
    $scope.updateSelection = function ($event, id) {
        var checkbox = $event.target;
        var action = (checkbox.checked ? 'add' : 'remove');
        updateSelected(action, id, checkbox.name);
    }
    $scope.isSelected = function (id) {
        return $scope.addEvaInfo.GoodDishes.indexOf(id) >= 0;
    }
    //添加评论
    $scope.addEva = function (u) {
        console.log(u);
        OrderListService.addeva(u)
            .success(function (resp) {
                if (resp == "OK") {
                    $('#myEvaModal').modal('hide');//关闭模态框
                    window.location.reload();//刷新当前页面
                } else {
                    alert(resp);
                }
            })
            .error(function (resp) { console.log(resp) })
    };
}]);
//查看订单详情
app.controller('OrderDetailController', ['$scope', '$http', '$location', '$window', 'OrderDetailService', function ($scope, $http, $location, $window, OrderDetailService) {
    //获取URL参数，即：获取商户ID。
    $scope.orderNum = $location.absUrl().substring($location.absUrl().lastIndexOf("=") + 1);
    var postOrderNum = {
        orderNum: $scope.orderNum
    }

    // 获取信息，是否允许评价
    $http.get('/Order/GetOrder_Key').success(function (resp) {
        if (resp != "" || resp != null) {
            console.log(resp[0]);
            $scope.ComOpen = resp[0].ComOpen; // 是否允许评价,1-是，0-否
            console.log($scope.ComOpen);
        } else {
            console.log("系统异常");
        }

    });

    //$scope.Detail = '';
    //获取订单ID
    OrderDetailService.getDetail(postOrderNum).success(function (resp) {
        console.log(resp);
        $scope.Detail = resp;
        $scope.EvaDishName = resp.FormDisheName;
        $scope.EvaDishID = resp.FormDisheID;
        $scope.addEvaInfo.FormID = resp.vof.FormID;
        //console.log($scope.Detail);
    });


    $scope.addEvaInfo = {
        FormID: '',
        EvaTxt: '',
        EvaStars: 1,
        GoodDishes: []
    };
    $scope.isStar1 = true;
    $scope.isStar2 = false;
    $scope.isStar3 = false;
    $scope.isStar4 = false;
    $scope.isStar5 = false;
    //评分
    $scope.putstar = function (star) {
        $scope.addEvaInfo.EvaStars = star;
        console.log($scope.addEvaInfo.EvaStars);
        if (star == 1) {
            $scope.isStar1 = true;
            $scope.isStar2 = false;
            $scope.isStar3 = false;
            $scope.isStar4 = false;
            $scope.isStar5 = false;
        } else if (star == 2) {
            $scope.isStar1 = true;
            $scope.isStar2 = true;
            $scope.isStar3 = false;
            $scope.isStar4 = false;
            $scope.isStar5 = false;
        } else if (star == 3) {
            $scope.isStar1 = true;
            $scope.isStar2 = true;
            $scope.isStar3 = true;
            $scope.isStar4 = false;
            $scope.isStar5 = false;
        } else if (star == 4) {
            $scope.isStar1 = true;
            $scope.isStar2 = true;
            $scope.isStar3 = true;
            $scope.isStar4 = true;
            $scope.isStar5 = false;
        } else if (star == 5) {
            $scope.isStar1 = true;
            $scope.isStar2 = true;
            $scope.isStar3 = true;
            $scope.isStar4 = true;
            $scope.isStar5 = true;
        }
        console.log($scope.isStar1)
        console.log($scope.isStar2)
        console.log($scope.isStar3)
        console.log($scope.isStar4)
        console.log($scope.isStar5)
    };

    //选择推荐菜
    var updateSelected = function (action, id, name) {
        if (action == 'add' && $scope.addEvaInfo.GoodDishes.indexOf(id) == -1) {
            $scope.addEvaInfo.GoodDishes.push(id);
        }
        if (action == 'remove' && $scope.addEvaInfo.GoodDishes.indexOf(id) != -1) {
            var idx = $scope.addEvaInfo.GoodDishes.indexOf(id);
            $scope.addEvaInfo.GoodDishes.splice(idx, 1);
        }
    }
    $scope.updateSelection = function ($event, id) {
        var checkbox = $event.target;
        var action = (checkbox.checked ? 'add' : 'remove');
        updateSelected(action, id, checkbox.name);
    }
    $scope.isSelected = function (id) {
        return $scope.addEvaInfo.GoodDishes.indexOf(id) >= 0;
    }

    //添加评论
    $scope.addEva = function (u) {
        console.log(u);
        OrderDetailService.addEva(u)
            .success(function (resp) {
                if (resp == "OK") {
                    //$('#myEvaModal').modal('hide');//关闭模态框
                    //window.location.reload();//刷新当前页面
                    $window.location.href = "/Order/OrderList";
                } else {
                    alert(resp);
                }
            })
            .error(function (resp) { console.log(resp) })
    };
}])
// 再付款
app.controller('RePaymentController', ['$scope', '$http', '$location', '$window', 'ReBookOrderService', function ($scope, $http, $location, $window, ReBookOrderService) {
    //获取URL参数，即：获取商户ID。
    console.log("进来了");
    var s = [];
    $scope.orderNum = $location.absUrl().substring($location.absUrl().lastIndexOf("MerID=") + 6);
    s = $scope.orderNum.split('&');
    $scope.NowFormID = $location.absUrl().substring($location.absUrl().lastIndexOf("FormID=") + 7);
    var postOrderNum = {
        MerID: s[0]
    }
    console.log($scope.NowFormID);
    console.log(postOrderNum);
    $scope.NowPeyID = '';
    //$scope.NowFormID = '';

    // 默认选择为派送
    var isTake1 = document.getElementById("isTake1");
    isTake1.className += " " + "zhuangtai";
    var isTake = 1; // 默认派送 1：派送；2：自取


    // 是否自取的事件
    $scope.take = function (v) {
        if (v == 1) {
            isTake = 1;
            var isTake1 = document.getElementById("isTake1");
            isTake1.className += " " + "zhuangtai";
            var isTake2 = document.getElementById("isTake2");
            isTake2.className = "xuanze f-right";

            var postData = {
                FormID: $scope.NowFormID,
                PayID: $scope.ddvm.selectionW.ID,
                lx: 1,
                isTake: 1,
            }

            console.log(postData);
            //计算优惠信息
            ReBookOrderService.ReBookOrder(postData)
                .success(function (resp) {
                    console.log("已计算优惠信息");
                    $scope.Total = resp.data.Total;
                    $scope.Discount = resp.data.Discount;
                })
                .error(function (resp) { console.log(resp) });
        } else {
            isTake = 2;
            var isTake2 = document.getElementById("isTake2");
            isTake2.className += " " + "zhuangtai";
            var isTake1 = document.getElementById("isTake1");
            isTake1.className = "xuanze f-right";

            var postData = {
                FormID: $scope.NowFormID,
                PayID: $scope.ddvm.selectionW.ID,
                lx: 1,
                isTake: 2,
            }

            console.log(postData);
            //计算优惠信息
            ReBookOrderService.ReBookOrder(postData)
                .success(function (resp) {
                    console.log("已计算优惠信息");
                    $scope.Total = resp.data.Total;
                    $scope.Discount = resp.data.Discount;
                })
                .error(function (resp) { console.log(resp) });
        }
    }

    $scope.aa = function (re) {
        console.log(re);
        for (var i in $scope.ddvm.paywalts) {
            if ($scope.ddvm.paywalts[i].bb = 2) {
            }
        }
        $scope.ddvm.selectionW = re
        $scope.ddvm.selectionW.bb = 1;
        console.log(1);
        var postData = {
            FormID: $scope.NowFormID,
            PayID: re.ID,
            lx: 1,
            isTake: isTake,
        }

        console.log(postData);
        //计算优惠信息
        ReBookOrderService.ReBookOrder(postData)
            .success(function (resp) {
                console.log("已计算优惠信息");
                $scope.Total = resp.data.Total;
                $scope.Discount = resp.data.Discount;
            })
            .error(function (resp) { console.log(resp) });
    }

    //var ddvm = $scope.ddvm = {};
    //ddvm.paywalts = [];//钱包数组
    //ddvm.selectionW = [];
    $scope.ddvm = {};
    $scope.ddvm.paywalts = [];//钱包数组
    $scope.ddvm.selectionW = [];
    //$scope.NowFormID = postOrderNum.orderNum;

    ReBookOrderService.getBasicInfoByMerID(postOrderNum)
        .success(function (resp) {
            //alert('adadadad');
            console.log(resp);
            $scope.ddvm.paywalts = resp.walt;//钱包集合
            $scope.ddvm.selectionW = $scope.ddvm.paywalts[0];//选择的钱包
            $scope.ddvm.selectionW.bb = 1;
            console.log($scope.ddvm.selectionW.ID);
            //alert('1:' + ddvm.selectionW.Name);
            //alert('2222');

            var postData = {
                FormID: $scope.NowFormID,
                //PayID: $scope.ddvm.selectionW.ID,
                PayID: "wxzf",
                lx: 1,
                isTake: isTake,
            }

            console.log(postData);
            //计算优惠信息
            ReBookOrderService.ReBookOrder(postData)
                .success(function (resp) {
                    console.log("初始化，已计算优惠");
                    $scope.Total = resp.data.Total;
                    $scope.Discount = resp.data.Discount;
                })
                .error(function (resp) { console.log(resp) });
        })
        .error(function (resp) { console.log(resp) });

    //监控钱包列表的选择变化
    $scope.$watch("ddvm.selectionW", function (newVal, oldVal) {
        //alert(vm.selectionW.ID + "|" + vm.selectionW.Name + "|" + vm.selectionW.PricType + "|" + vm.selectionW.PriTxt);
        //定义返回实体格式
        var whichwalt = {
            ID: '',
            Name: '',
            PricType: 0,
            PriTxt: '',
        };
        whichwalt = newVal;
        $scope.NowPeyID = whichwalt.ID;
        //alert('ID:' + $scope.NowPeyID);
        //console.log('newVal');
        //组装数据包
        var postData = {
            FormID: $scope.NowFormID,
            //PayID: $scope.NowPeyID,
            PayID: "wxzf",
            lx: 1,
            isTake: isTake,
        }
        // alert('FormID:' + postData.FormID + ' lx' + postData.lx + ' PayID:' + postData.PayID);
        //计算优惠信息
        ReBookOrderService.ReBookOrder(postData)
            .success(function (resp) {
                //console.log(resp);
                //alert('33');
                //$scope.DishList = resp.data.DishList;
                //$scope.CountArr = resp.data.CountArr;
                //$scope.Total = resp.data.Total;
                //$scope.Discount = resp.data.Discount;
                //$scope.TotalPoint = resp.data.TotalPoint;
                //$scope.ShopInfo = resp.shopinfo;

                //$scope.backCount = function (dishesid) {
                //    for (var i in $scope.DishList) {
                //        if ($scope.DishList[i].DishesID == dishesid) {
                //            return $scope.CountArr[i];
                //        }
                //    }
                //}
                //$scope.packTotal = function () {
                //    $scope.varlist.pack = 0;
                //    for (var j = 0; j < $scope.CountArr.length; j++) {
                //        $scope.varlist.pack = $scope.varlist.pack + $scope.CountArr[j] * $scope.DishList[j].DelPackMon;//商品数量*商品包装费
                //    }
                //    return $scope.varlist.pack;
                //}
            })
            .error(function (resp) { console.log(resp) });
    }, true);

    //  lx:3删除订单
    $scope.DeleteBookOrder = function (FormID, NowPeyID) {
        if ($scope.NowFormID != "") {
            var dialog = jqueryAlert({
                'title': '确认提示',
                'content': "是否确认取消 " + $scope.NowFormID + " 这条订单!",
                'modal': true,
                'buttons': {
                    '取消': function () {
                        dialog.close();
                    },
                    '确定': function () {
                        //组装数据包
                        var postData = {
                            FormID: $scope.NowFormID,
                            PayID: $scope.NowPeyID,
                            lx: 3,
                            isTake: isTake,
                        }
                        //alert("2222222");
                        ReBookOrderService.DeleteBookOrder(postData)
                            .success(function (resp) {
                                if (resp.bs == '1') {
                                    jqueryAlert({
                                        'content': '删除订单成功！'
                                    });
                                    setTimeout(function () { window.location.href = "/Order/OrderList"; }, 1000);                                    
                                }
                                else {
                                    jqueryAlert({
                                        'content': '删除订单失败！' + resp.mes
                                    });
                                    //$window.location.href = "/PersonalCenter/orderlist";
                                    //alert("2222222");
                                    //window.location.href = "/PersonalCenter/orderlist";
                                }
                                //window.location.href = "http://www.nnzbzh.cn/";
                            })
                            .error(function (resp) { console.log(resp) });
                        // window.location.href = "http://www.nnzbzh.cn/";
                        dialog.close();
                    }
                }
            })
        };
    }

    //  lx:3修改订单支付方式
    $scope.PayBookOrder = function (FormID, NowPeyID) {
        //组装数据包
        var postData = {
            FormID: $scope.NowFormID,
            PayID: $scope.NowPeyID,
            lx: 2,
            isTake: isTake,
        }
        //alert("2222222");
        ReBookOrderService.PayBookOrder(postData)
            .success(function (resp) {
                console.log(resp)
                if (resp == "10") {
                    window.location = '/Order/TiJiaoOrder'; //打开确认订单页
                    //alert('修改支付方式成功');
                    //$http.get('/Order/tjjs'  ).success(function (data) {
                    //    if (resp == "10") {
                    //        window.location = '/Order/TiJiaoOrder'; //打开确认订单页
                    //    } else if (data == "11") {
                    //        window.location = '/WeChatPay/Index';//打开微信支付页面
                    //    }
                    //    else {
                    //        window.location = '/PersonalCenter/OrgOrderList';
                    //    }
                    //}).error(function(data, status, headers, config) {  
                    //    window.location = '/PersonalCenter/OrgOrderList';
                    //});  
                    //$http.get(
                    //$.get("/Order/tjjs", function (data) {
                    //    window.location = '/PersonalCenter/OrgOrderList';
                    //});
                    //window.location.href = "/PersonalCenter/orderlist";
                }
                else if (resp.msg != undefined) {
                    //window.location = '/WeChatPay/Index';//打开微信支付页面
                    //微信支付
                    if (resp.msg == 'success') {
                        //alert(resp.appId);
                        onBridgeReady(resp);

                        function onBridgeReady(resp) {
                            WeixinJSBridge.invoke(
                                'getBrandWCPayRequest', {
                                    "appId": resp.appId,     //公众号名称，由商户传入
                                    "timeStamp": resp.timeStamp,         //时间戳，自1970年以来的秒数
                                    "nonceStr": resp.nonceStr, //随机串
                                    "package": resp.packageValue,
                                    "signType": "MD5",         //微信签名方式:
                                    "paySign": resp.paySign //微信签名
                                },
                                function (res) {
                                    if (res.err_msg == "get_brand_wcpay_request:ok") {      //支付成功
                                        //alert("支付成功,请稍后查询余额,如有疑问,请联系管理员.");
                                        ReBookOrderService.UpdateFormIsPay()
                                            .success(function (resp) {
                                                //console.log(resp);
                                                if (resp.BS == '1') {
                                                    window.location.href = '/Order/OrderList';
                                                }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                                            })
                                            .error(function (resp) { console.log(resp) });
                                    }
                                    else if (res.err_msg == "get_brand_wcpay_request:cancel") {      //支付过程中用户取消
                                        jqueryAlert({
                                            'content': '支付过程中用户取消，请重新支付！'
                                        });
                                    }
                                    else if (res.err_msg == "get_brand_wcpay_request:fail") {      //支付失败
                                        jqueryAlert({
                                            'content': '支付失败，请重新支付！'
                                        });
                                    }
                                }
                            );
                        }
                        //window.location = '/JsApiPay/Index';//打开微信支付页面----------jsapi
                    }
                }
                else {
                    jqueryAlert({
                        'content': '修改支付方式失败：' + resp.mes
                    });
                    //window.location = '/PersonalCenter/OrgOrderList';
                }
            })
            .error(function (resp) { console.log(resp) });
    }
}])


app.factory('WaltandAddressService', ['$http', function ($http) {
    var list = function () {
        return $http.post('/Order/getBasicInfo');
    }
    //获取地址列表
    var list_address = function (postdata) {
        return $http.post('/Order/GetUserSendAddr', postdata);
    }
    return {
        list: function () {
            return list();
        },
        list_address: function (postdata) {
            return list_address(postdata);
        }
    }
}]);

app.factory('GetSendAddFromMerIdService', ['$http', function ($http) {
    //根据商户id获取该商户下的所有派送范围
    var list = function () {
        return $http.post('/Order/getallsendfrommerid');
    }
    return {
        list: function () {
            return list();
        }
    };
}]);

app.factory('OrderService', ['$http', function ($http) {
    //计算优惠价格
    var list = function (whichwalt) {
        return $http.post('/Order/getOrderTotal', whichwalt);
    }
    //用户确认下单
    var book = function (postData) {
        return $http.post('/Order/BookOrder', postData);
    }
    return {
        list: function (whichwalt) {
            return list(whichwalt);
        },
        book: function (postData) {
            return book(postData);
        }
    }
}]);
app.factory('OrderListService', ['$http', function ($http) {
    var list = function (postData) {
        //return $http.post('/Order/getOrderList', postData);
        return $http.post('/Order/getOrderList2', postData);
    }
    return {
        list: function (postData) { return list(postData); }
    }
}]);
app.factory('OrderDetailService', ['$http', function ($http) {
    var getDetail = function (postData) {
        return $http.post('/Order/getDetail', postData);
    }
    var addEva = function (postData) {
        return $http.post('/Order/addOrderEva', postData);
    }
    return {
        getDetail: function (postData) { return getDetail(postData); },
        addEva: function (postData) { return addEva(postData); }
    }
}]);

app.factory('FormbyService', ['$http', function ($http) {
    var Formby = function (postData) {
        return $http.post('/Form/Formby', postData);
    }
    return {
        Formby: function (postData) { return Formby(postData); }
    }
}]);

app.factory('ReBookOrderService', ['$http', function ($http) { //根据原订单计算优惠价格）
    var ReBookOrder = function (postData) {     // 根据原订单计算优惠价格）
        return $http.post('/Order/ReBookOrder', postData);
    }
    var getBasicInfoByMerID = function (postData) {  //获取指定商户的可使用钱包信息
        return $http.post('/Order/getBasicInfoByMerID', postData);
    }
    var DeleteBookOrder = function (postData) {     // 删除订单
        return $http.post('/Order/DeleteBookOrder', postData);
    }
    var PayBookOrder = function (postData) {     // 修改订单支付方式
        return $http.post('/Order/PayBookOrder', postData);
    }
    var UpdateFormIsPay = function () {     //用户付款成功后更新订单支付状态
        return $http.post('/Order/UpdateFormIsPay');
    }
    return {
        ReBookOrder: function (postData) {
            return ReBookOrder(postData);
        },
        getBasicInfoByMerID: function (postData) {
            return getBasicInfoByMerID(postData);
        },
        DeleteBookOrder: function (postData) {
            return DeleteBookOrder(postData);
        },
        PayBookOrder: function (postData) {
            return PayBookOrder(postData);
        },
        UpdateFormIsPay: function () {
            return UpdateFormIsPay();
        }
    }
}]);

